package com.oscarmovie.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.oscarmovie.Constants;
import com.oscarmovie.model.Role;
import com.oscarmovie.service.RoleService;

public class RoleAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private RoleService roleService;
	private Role role;
	private List<Role> roles;

	public String execute() throws Exception {
		throw new Exception("Please specify method name!");
	}
	public String add() throws Exception {
		setRole(null);
		return Constants.ADD;
	}
	public String edit() throws Exception {
		loadAll();
		load();
		return Constants.EDIT;
	}
	public String save() throws Exception {
		roleService.save(role);
		return edit();
	}

	public String load() throws Exception {
		this.setRole(roleService.load(role.getId()));
		return SUCCESS;
	}
	
	public String loadAll() throws Exception {
		this.roles = roleService.loadAll();
		return SUCCESS;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public Role getRole() {
		return role;
	}


}
